package com.kehao.newcoder;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class NC41Solution {

    public int maxLength (int[] arr) {
        Set<Integer> set = new HashSet<>();
        int i = 0;int j = 0;
        int result = 0;
        while (j<arr.length){
            if(set.contains(arr[j])){
                set.remove(arr[i]);
                i++;
            }else {
                set.add(arr[j]);
                j++;
            }
            result = Integer.max(j-i,result);
        }
        return result;
    }

}
